<?php
/**
 * @copyright Copyright (C) 2010 redCOMPONENT.com. All rights reserved.
 * @license GNU/GPL, see license.txt or http://www.gnu.org/copyleft/gpl.html
 * Developed by email@recomponent.com - redCOMPONENT.com
 *
 * redSHOP can be downloaded from www.redcomponent.com
 * redSHOP is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.
 *
 * You should have received a copy of the GNU General Public License
 * along with redSHOP; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
defined('_JEXEC') or die('Restricted access');
require_once( JPATH_COMPONENT_SITE.DS.'helpers'.DS.'product.php' );
$producthelper = new producthelper();
$redconfig = new Redconfiguration();


$option = JRequest::getVar('option','','request','string');
$tax_group_id =  JRequest::getVar('tax_group_id','','request','string');

?>
<script language="javascript" type="text/javascript">

Joomla.submitbutton = function(pressbutton) {submitbutton(pressbutton);}
submitbutton = function(pressbutton){
var form = document.adminForm;
   if (pressbutton)
    {form.task.value=pressbutton;}

	 if ((pressbutton=='add')||(pressbutton=='edit')||(pressbutton=='publish')||(pressbutton=='unpublish')
	 ||(pressbutton=='remove') ||(pressbutton=='saveorder')||(pressbutton=='orderup') || (pressbutton=='orderdown') )
	 {
	  form.view.value="tax_detail";
	 }
	try {
		form.onsubmit();
		}
	catch(e){}

	form.submit();
  }

</script>
<form action="<?php echo 'index.php?option='.$option; ?>" method="post" name="adminForm" id="adminForm" >
<div id="editcell">
	<table class="adminlist">
	<thead>
		<tr>
			<th width="5%">
				<?php echo JText::_('COM_REDSHOP_NUM' ); ?>
			</th>
			<th width="5%">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->media ); ?>);" />
			</th>
			<th class="title">
				<?php echo JHTML::_('grid.sort', 'COM_REDSHOP_TAX_COUNTRY', 'tax_country', $this->lists['order_Dir'], $this->lists['order'] ); ?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'COM_REDSHOP_TAX_STATE', 'tax_state', $this->lists['order_Dir'], $this->lists['order'] ); ?>
		 	</th>
			<th width="5%" nowrap="nowrap">
				<?php echo JHTML::_('grid.sort', 'COM_REDSHOP_TAX_RATE', 'tax_rate', $this->lists['order_Dir'], $this->lists['order'] ); ?>
			</th>

		</tr>
	</thead>
	<?php
	$k = 0;
	for ($i=0;$i<count($this->media); $i++)
	{
		$row = &$this->media[$i];
        $country_id=$redconfig->getCountryId($row->tax_country);
        $state_code = $redconfig->getStateCode($country_id, $row->tax_state);

        $row->id = $row->tax_rate_id;

		$link 	= JRoute::_( 'index.php?option='.$option.'&view=tax_detail&task=edit&cid[]='. $row->tax_rate_id );


		?>
		<tr class="<?php echo "row$k"; ?>">
			<td align="center">
				<?php echo $this->pagination->getRowOffset( $i ); ?>
			</td align="center">
			<td align="center">
			<?php echo JHTML::_('grid.id', $i, $row->id ); ?>
			</td>
			<td align="center">
			<a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_REDSHOP_EDIT_TAX' ); ?>"><?php echo $row->tax_country; ?></a>
			</td>
			<td align="center">
				<?php
				echo $state_code; ?>
			</td>

			<td align="center">
				<?php echo number_format($row->tax_rate*100,2,PRICE_SEPERATOR,THOUSAND_SEPERATOR) . " %";//number_format($row->tax_rate,2,PRICE_SEPERATOR,THOUSAND_SEPERATOR); ?>
			</td>
		</tr>
		<?php
		$k = 1 - $k;
	}
	?>

<tfoot>
		<td colspan="9">
			<?php echo $this->pagination->getListFooter(); ?>
		</td>
	</tfoot>
	</table>
</div>

<input type="hidden" name="view" value="tax" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="tax_group_id" value="<?php echo $this->lists['tax_group_id']; ?>" />
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
</form>
